<?php
$images = isset($images) ? $images : array();
$limit = isset($limit) ? $limit : 1;
?>
<div class="a_upload">
    <a class="a_upload_file" href="javascript:$('#file_upload').uploadify('upload','*');">upload</a>
</div>
<input type="file" name="file_upload" id="file_upload" class="btn btn-large btn-inverse"/>



<div id="imgShow">
    <?php if (!empty($images)): ?>
        <?php foreach ($images as $img): ?>
            <div class="upload_img">
                <img src="<?php echo service_image::getThumb($img['src']); ?>" width="100" height="100" />
            </div>
        <?php endforeach; ?>
    <?php endif; ?>
</div>
<script type="text/javascript" src="<?php echo public_path('js/uploadify/jquery.uploadify-3.1.min.js'); ?>"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#file_upload").uploadify({
            'swf' : "<?php echo public_path('js/uploadify/uploadify.swf'); ?>",
            'uploader':"<?php echo url('image/upload'); ?>",
            'uploadLimit':"<?php echo $limit; ?>",
            'auto':false,
            'buttonText':'select',
            'fileSizeLimit': '2MB',
            'fileTypeExts':	'*.gif;*.jpg;*.jpeg;*.png',
            'onUploadSuccess':function(file,data,response){
                var str = "<div class='upload_img'><img src='"+data+"' width='100' height='100' />";
                str = str+"<input type='hidden' name='img[]' value='"+data+"' /></div>";
                if(<?php echo $limit;?> == 1){
					$("#imgShow").html(str);	
				}else{
					$("#imgShow").append(str);
				}
            }
        });		
    });
</script>
